import store from 'store';
import {history} from 'umi'

export const TOKEN_LOCA_NAME = 'token';
export const  USER_INFO_LOCAL_NAME = 'userInfo';
export const THEME_LOCAL_NAME = 'theme'
export type THEME_VALUE ='drak'|'algor';
// 记住密码
export const RTP_LOCAL_NAME = 'isrtp';

// 定义一个账户和密码的本地变量
export const ACCOUNT_LOCAL_NAME = 'account';
export const PASSWORD_LOCAL_NAME = 'password';

// 写一下账户和密码的存储和读取函数
export function setAccount(account: string) {
  store.set(ACCOUNT_LOCAL_NAME, account);
}
export function getAccount() {
  return store.get(ACCOUNT_LOCAL_NAME);
}

export function setPassword(password: string) {
  store.set(PASSWORD_LOCAL_NAME, password);
}


export function getPassword() {
  return store.get(PASSWORD_LOCAL_NAME);
} 

export function isLogin() {
  return !!store.get(TOKEN_LOCA_NAME);
}
export function getUserInfo() {
  return store.get(USER_INFO_LOCAL_NAME);
}


export function loginOut() {
    store.remove(TOKEN_LOCA_NAME);
    store.remove(USER_INFO_LOCAL_NAME);
    history.push('/login')
    location.reload()
}

export function setTheme(theme:THEME_VALUE){
  store.set(THEME_LOCAL_NAME,theme)
}
export function getTheme():THEME_VALUE|null{
  return store.get(THEME_LOCAL_NAME)
}

export function setRTP(isRtp:boolean){
  store.set(RTP_LOCAL_NAME,isRtp)
}

export function getRTP():boolean{
  return store.get(RTP_LOCAL_NAME)
}